# Clear previous model
wipe

# Set model dimensions and degrees of freedom
model BasicBuilder -ndm 2 -ndf 3

# Create nodes
node 1 0.0 0.0
node 2 0.0 3.0
node 3 3.0 3.0
node 4 3.0 0.0

# Set boundary conditions
fix 1 1 1 1
fix 4 1 1 1

# Define material
uniaxialMaterial Elastic 1 200000.0

# Define coordinate transformation
geomTransf Linear 1

# Create elements
element elasticBeamColumn 1 1 2 0.01 200000.0 0.0001 1
element elasticBeamColumn 2 2 3 0.01 200000.0 0.0001 1
element elasticBeamColumn 3 3 4 0.01 200000.0 0.0001 1

# Create recorder
recorder Node -file node_disp.out -time -node 2 3 -dof 1 2 3 disp

# Create UDP recorder - Send node 2's x-direction displacement to specified IP and port
# Parameters: nodeTag dof serverIP port
udpRecorder 2 1 127.0.0.1 8090

# Set up analysis
system BandSPD
constraints Plain
numberer RCM
test NormDispIncr 1.0e-8 10 0
algorithm Newton
integrator LoadControl 0.1
analysis Static

# Create UDP load pattern - Receive loading data from port 8091
# Parameters: patternTag nodeTag dof port
udpPattern 1 3 2 8091

# Add small static load to ensure system response
pattern Plain 2 Linear {
    load 3 0.0 -0.1 0.0
}

# Run analysis
puts "Analysis starting..."
puts "Running 100 steps, receiving UDP loads at each step"
puts "Make sure UDP sender program (udp_sender.py) is running"

# Execute analysis
analyze 100

puts "Analysis complete!"
puts "Check node_disp.out file for displacement results"
puts "UDP recorder has sent displacement data to 127.0.0.1:8090"